﻿using System.Linq;

namespace Sidvall.LogManager.UI.Entities
{
	public sealed partial class ServerConnection
	{
		#region GetServerManager

		public static ServerManager GetServerManager(int? serverConnectionId)
		{
			if (serverConnectionId == null)
				return null;
			return (from o in Sidvall.LogManager.UI.SystemContext.Current.ServerManagers
					where o.ServerConnectionId == serverConnectionId.Value
					select o).FirstOrDefault();
		}

		#endregion
		#region GetServerConnection

		public static ServerConnection GetServerConnection(int serverConnectionId)
		{
			Sidvall.LogManager.Net.Services.V1.ServerConnection serverConnection;
			ServerConnection item;

			serverConnection = (from o in Sidvall.LogManager.SystemContext.Current.UserConfiguration.ServerConnections.Items
								where o.ServerConnectionId == serverConnectionId
								select o).FirstOrDefault();
			if (serverConnection == null)
				return null;
			item = new ServerConnection();
			item.Import(serverConnection, Sidvall.Data.CopySettings.FullCopyAll(Sidvall.Data.DataRowContextOption.None, null));

			return item;
		}

		#endregion
	}
}